package com.dadi.broadcastdemo1;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

/**
 * author: 韦敏敏
 * date: 2019/12/29 0029
 */
public class MainFragment extends Fragment {
    String TAG = "MainFragment";
    public MainFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View myView = inflater.inflate(R.layout.layout_fragment_main, container, false);
        myView.findViewById(R.id.btnSendStatic).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                // 发送静态广播
                Intent staticIntent = new Intent(MainActivity.STATIC_ACTION);
                staticIntent.setPackage("com.dadi.broadcastdemo1");
                getActivity().sendBroadcast(staticIntent);
            }
        });
        myView.findViewById(R.id.btnSendDynamic).setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                // 发送动态广播
                Intent dynamicIntent = new Intent(MainActivity.DYNAMIC_ACTION);
                LocalBroadcastManager.getInstance(getContext()).sendBroadcast(dynamicIntent);
            }
        });
        return myView;

    }
}
